package JDBCUtil;

import java.sql.*;
import java.util.ResourceBundle;

public class JDBCUtil {
    private static String driver ;
    private static String url ;
    private static String username ;
    private static String password ;
    static {
        try {
            // ResourceBundle resourceBundle = ResourceBundle.getBundle("db");
            driver ="com.mysql.jdbc.Driver";
            url = "jdbc:mysql://localhost:3306/test?useSSL=false";
            username = "root";
            password = "root";
            Class.forName(driver);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static Connection getConnection() throws Exception{
        return DriverManager.getConnection(url, username, password);
    }
    public static void close(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet){
        if (resultSet != null){
            try {
                resultSet.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (preparedStatement != null){
            try {
                preparedStatement.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        if (connection != null){
            try {
                connection.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }

    }
}
